﻿using GalaSoft.MvvmLight;
using Northwind.Interfaces;
using Northwind.Interfaces.Data.Model;
using GalaSoft.MvvmLight.Command;
using Northwind.ViewModel.Messeges;
using GalaSoft.MvvmLight.Messaging;

namespace Northwind.ViewModel
{
    public class OrderControlPanelViewModel : ComponentsViewModel
    {
        CommandViewModel _createOrderCommandViewModel;
        OrdersViewModel _ordersViewModel;

        public OrderControlPanelViewModel()
            : base(Strings.OrderControlPanelName)
        {
        }

        protected override void AddComponents()
        {
            // TODO: Implement me
            Components.Add(_ordersViewModel);
            Components.Add(_createOrderCommandViewModel);
        }

        protected override void Initialize()
        {
            base.Initialize();

            _ordersViewModel = new OrdersViewModel();
            _createOrderCommandViewModel =
                new CommandViewModel(Strings.CreateOrder,
                    new RelayCommand(OnCreateOrder));
        }

        #region Commands Handlers

        private void OnCreateOrder()
        {
            Messenger.Default.Send<ShowNewOrderWizard>(new ShowNewOrderWizard());
        }

        //private void OnCancelOrder()
        //{
        //    if (SelectedOrder == null)
        //    {
        //        return;
        //    }

        //    //_ordersViewModel.Orders.Remove(SelectedOrder);
        //    _ordersViewModel.CancelOrder(SelectedOrder);
        //    SelectedOrder = null;
        //    //TODO: Logic to delete order
        //}

        //private bool IsCancelOrderAllowed()
        //{
        //    return SelectedOrder != null;
        //}

        #endregion Command Handlers

    }
}